<template>
  <!-- 放置一个图标 -->
  <div style="display:inline-block">
    <svg-icon :icon-class="isFullScreen ? 'exit-fullscreen':'fullscreen'" class="c" @click="toggleScreen" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFullScreen: false
    }
  },
  created() {
  // ESC会改变当前的全屏状态
    // screenfull是插件，它自带事件监听 on
    // screenfull.isFullscreen ：插件自带的属性，表示当前是否处于全屏状态
    screenfull.on('change', () => {
      // console.log('当前是否是全屏', screenfull.isFullscreen)
      this.isFullScreen = screenfull.isFullscreen
    })
  },
  methods: {
    toggleScreen() {
      screenfull.toggle()
      this.isFullScreen = !this.isFullScreen
    }
  }
}

</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;

  cursor: pointer;
}
.c {
    color: #fff;
    // animation: 动画名，动画时间，动画延迟，动画曲线，动画次数
    animation: fullscreen 0.1s infinite;
}
@keyframes fullscreen {
    50% {
        transform: rotate(360deg);
    }
    100% {
        transform: rotate(-360deg);
    }
}
</style>
